package PriorityQueues;

import java.util.Comparator;
import java.util.PriorityQueue;

public class PriorityQueues {
    public static void main(String[] args) {




    }
}
class Solution {
    public int[] smallestK(int[] arr, int k) {
        int[] a = new int[k];
        if(k == 0) {
            return a;
        }
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        for (int i = 0;i < k ;i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int i = k ;i < arr.length;i++) {
            if (priorityQueue.peek() > arr[i]) {
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        for (int i = 0;i < k;i++){
            a[i] = priorityQueue.poll();
        }
        return a;
    }
}
